$("#count").blur(function () {
    let count = $("#count").val();
    if(count < 1){
        count = 1;
    }
    parseInt(count);
    $("#count").val(count);
});

$("#add").click(function () {
    let count = $("#count").val();
    count++;
    $("#count").val(count);
    console.log("add")
});

$("#sub").click(function () {
    let count = $("#count").val();
    count--;
    if(count < 1){
        count = 1;
    }
    $("#count").val(count);
});

var baseUrl = "http://localhost:8099";
$(".addProductToCart").click(function () {
    let productId = $("#productId").html();
    let count = $("#count").val();
    //let localhost = $("#localhost").html();
    console.log(productId,count);
    $.ajax({
        url: baseUrl + "/cart/addProductToCart",
        type: "post",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        data: JSON.stringify({"productId":productId,"count":count}),
        success: function (data) {
            window.location.href = baseUrl +"/cart/cart.html";
        }

    })


})

